﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Mvc;
using FzWeb.Models;
using System.Collections.Generic;

namespace FzWeb.Filter
{
    public class CompanyFilter : FilterAttribute,IActionFilter
    {
        #region IActionFilter 成员
        private CompanyService companyService = new CompanyService();
        private static FzWeb.Models.Menu selectMenu;
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            
        }

        public void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //设置menu
            IList<FzWeb.Models.Menu> menus;
            if (filterContext.Controller.TempData["menus"] == null)
            {
                menus = companyService.GetCompanyMenu();
                filterContext.Controller.TempData["menus"] = menus;
            }
            else
            {
                menus = filterContext.Controller.TempData["menus"] as IList<FzWeb.Models.Menu>;
            }
            try
            {
                selectMenu = companyService.GetCompanyMenu(filterContext.RouteData.Values["action"].ToString());
            }
            catch
            {
            }
            filterContext.Controller.TempData["selectMenu"] = selectMenu;
            
        }

        #endregion
    }
}
